﻿using System;

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define max(a, b) ((a) > (b) ? (a) : (b))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define min(a, b) ((a) > (b) ? (b) : (a))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define abs(a) (((a) >= 0) ? (a) : -(a))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ntohl(num) ((num << 24) | ((num & 0x0000FF00) << 8) | ((num & 0x00FF0000) >> 8) | (num >> 24))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define _bitm(v, a, b, size) (((v) << ((size) - (b)-1)) >> ((size) - (b)-1 + (a)))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define bit1(v, a) (((v) >> (a)) & 0b1)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define bitm64(v, a, b) _bitm(v, a, b, 64)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define bitm(v, a, b) _bitm(v, a, b, 32)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define bitm16(v, a, b) _bitm(v, a, b, 16)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define bitm8(v, a, b) _bitm(v, a, b, 8)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define bitm4(v, a, b) _bitm(v, a, b, 4)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define val_bits(val) ((uint32)sizeof(val) << 3)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define sign_extend(val, val_bits) (((int32)((val) << (32 - (val_bits)))) >> (32 - (val_bits)))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define sign_extend_e(val) (((int32)((val) << (32 - val_bits(val)))) >> (32 - val_bits(val)))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define inst_bm(from, to) bitm(inst, from, to)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define inst_b1(pos) bit1(inst, pos)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define inst_b4(from) inst_bm(from, from + 3)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define inst_b8(from) inst_bm(from, from + 7)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define inst_b16(from) inst_bm(from, from + 15)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define inst_b24(from) inst_bm(from, from + 23)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define println(fmt, ...) printf(fmt, ##__VA_ARGS__); printf("\n")
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define logd(fmt, ...) printf("[DEBUG] "); println(fmt, ##__VA_ARGS__)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define loge(fmt, ...) printf("[ERROR] "); println(fmt, ##__VA_ARGS__)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define logw(fmt, ...) printf("[WARN]  "); println(fmt, ##__VA_ARGS__)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define logi(fmt, ...) printf("[LOG]   "); println(fmt, ##__VA_ARGS__)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define null ((void *)0)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define vmpt_real(type, p) ((type *)((vm->cpu->mem->buffer) + (p)))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define logsysc(fmt, ...) printf("[SYSCAL] "); println(fmt, ##__VA_ARGS__)
/**
 * 这个文件用于获取mrp文件的信息
 */




//mrp信息结构
public class mrp_info_t
{
	public string name = new string(new char[12]); //内部名
	public string showName = new string(new char[24]); //显示名
	public uint version; //版本号
	public uint appid; //appid
	public string author = new string(new char[40]); //作者
	public string desc = new string(new char[64]); //介绍
	//这两个和上面的差不多吧，不知道为什么要设置这么两个，待解...
	public uint ver; //版本号
	public uint id; //appid
}

//mrp内部文件信息
public class mrp_file_info
{
	public string name = new string(new char[DefineConstants.MRP_MAX_INNEER_NAME_LEN]); //文件名
	public uint offset; //文件偏移
	public uint size; //文件长度
	public bool isgzip; //是不是gzip编码
}

//mrp读取器定义
public class mrp_reader_t
{
	public FILE fd; //文件指针
	public mrp_info_t info = new mrp_info_t(); //mrp信息
	public mrp_file_info[] files = Arrays.InitializeWithDefaultInstances<mrp_file_info>(DefineConstants.MRP_MAX_INNEER_FILE); //mrp文件列表
	public uint data_offset; //数据部分位置
	public uint list_offset; //文件列表开始位置
	public uint file_len; //文件列表长度
}

//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ARCH_VER ARCH_V_4
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define loginst(name, hex) println("[INST]  name=%s, hex=0x%08x", name, hex)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define loginst(name, hex)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define lsl8(val, shift) ((uint8)(val) << (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define asl8(val, shift) ((int8)(val) << (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define lsr8(val, shift) ((uint8)(val) >> (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define asr8(val, shift) ((int8)(val) >> (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ror8(val, shift) (lsr8(val, shift) | lsl8(val, (8 - (shift))))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define lsl16(val, shift) ((uint16)(val) << (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define asl16(val, shift) ((int16)(val) << (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define lsr16(val, shift) ((uint16)(val) >> (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define asr16(val, shift) ((int16)(val) >> (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ror16(val, shift) (lsr16(val, shift) | lsl16(val, (16 - (shift))))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define lsl(val, shift) ((uint32)(val) << (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define asl(val, shift) ((int32)(val) << (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define lsr(val, shift) ((uint32)(val) >> (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define asr(val, shift) ((int32)(val) >> (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ror(val, shift) (lsr(val, shift) | lsl(val, (32 - (shift))))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define lsl64(val, shift) ((uint64)(val) << (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define asl64(val, shift) ((int64)(val) << (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define lsr64(val, shift) ((uint64)(val) >> (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define asr64(val, shift) ((int64)(val) >> (shift))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ror64(val, shift) (lsr64(val, shift) | lsl64(val, (64 - (shift))))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define regv(R) (st->registers[R])
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define even(num) (((num)&0x0001) == 0)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define cond_ok() check_cond(st, inst)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define has_reg_m4(reg) ((inst >> reg) & 0b0001)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define ldm_rn_pc_check() if (((inst >> 16) & 0x000f) == r_pc) return EXEC_UNPREDICTABLE
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define overflow_add(result, num1, num2) (((result) ^ (num1)) & ((result) ^ (num2)) & 0x80000000)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define overflow_sub(result, num1, num2) overflow_add(num1, result, num2)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define carry(result, num1) ((result) < (num1))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define carry8(res) ((res)&0x100)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define carry16(res) ((res)&0x10000)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define borrow8(res) ((res)&0x100)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define borrow16(res) ((res)&0x10000)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define mr_ret(val) (vm->cpu->registers[0] = (val))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define mrst (vm->mem->mr_state)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define vm_mem_offset(addr) ((uint8 *)(addr) - (uint8 *)(vm->cpu->mem->buffer))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define vm_mem_buf (vm->cpu->mem->buffer)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define vmreg(i) (vm->cpu->registers[i])
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define vmstack(i) (*((uint32 *)(vm_mem_buf + vmreg(r_sp)) + i))
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define MR_SPRITE_INDEX_MASK (0x03FF)
//C++ TO C# CONVERTER CRACKED BY X-CRACKER 2017 NOTE: The following #define macro was replaced in-line:
//ORIGINAL LINE: #define MR_SPRITE_TRANSPARENT (0x0400)

//mrp头信息
//public class mrp_head_info
//{
//	public string magic = new string(new char[4]); //这个没什么啦
//	public uint data_offset; //数据部分位置
//	public uint mrp_size; //总字节数
//	public uint list_offset; //文件列表开始位置
//	public string name = new string(new char[12]); //内部名
//	public string showName = new string(new char[24]); //显示名
//	public string imei = new string(new char[16]); //串号
//	public uint version; //版本号
//	public uint appid; //appid
//	public string _1 = new string(new char[12]); //未知
//	public string author = new string(new char[40]); //作者
//	public string desc = new string(new char[64]); //介绍
//	public uint ver; //版本号
//	public uint id; //appid

//	/*
//	这些就不管了。
//	// 192-196		版本ID十六进制值
//	// 196-200		appid十六进制值
//	200-240		未知
//	*/
//}

public unsafe struct mrp_head_info
{
	public fixed sbyte magic[4]; //这个没什么啦
	public uint data_offset; //数据部分位置
	public uint mrp_size; //总字节数
	public uint list_offset; //文件列表开始位置
	public fixed byte name[12]; //内部名
	public fixed byte showName [24]; //显示名
	public fixed byte imei [16]; //串号
	public uint version; //版本号
	public uint appid; //appid
	public fixed byte _1[12]; //未知
	public fixed byte author [40]; //作者
	public fixed byte desc [64]; //介绍
	public uint ver; //版本号
	public uint id; //appid

	/*
	这些就不管了。
	// 192-196		版本ID十六进制值
	// 196-200		appid十六进制值
	200-240		未知
	*/
}
